<script>
	function isNumeric(sText,addChars)
	{
	   var ValidChars = "0123456789"+addChars;
	   var IsNumber=true;
	   var Char; 
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
	      { 
	      Char = sText.charAt(i); 
	      if (ValidChars.indexOf(Char) == -1) 
	         {
	         IsNumber = false;
	         }
	      }
	   return IsNumber;
	}
	function displayNumeric(ctrl)
	{
		if(!isNumeric(ctrl.value,",")||ctrl.value=="")
		{
			ctrl.value="0";		
		}
		else
		{
			tmp="";
			for(i=0;i<ctrl.value.length;i++)
			{
				if(ctrl.value.charAt(i)!=",")
					tmp+=ctrl.value.charAt(i);
			}
			while(tmp.charAt(0)=="0"&&tmp.length>0)
			{
				tmp=tmp.substr(1)
			}
			tmp2="";
			j=0;
			for(i=tmp.length-1;i>=0;i--)
			{
				if(j%3==0&&j>0)	
					tmp2=tmp.charAt(i)+","+tmp2;		
				else
					tmp2=tmp.charAt(i)+tmp2;		
				j++;
			}
			
			ctrl.value=tmp2;
		}
	}
	function checkForm()
	{
		if(document.f.name.value=="")
		{
			alert('Vui lòng điền `Tên hàng`!');
			document.f.name.focus();
			return false;
		}
		if(document.getElementById('unit2').disabled==false&&document.getElementById('unit2').value=='')
		{
			alert('Vui lòng điền hoặc chọn `ĐVT`!');
			document.getElementById('unit2').focus();
			return false;
		}
	}
</script>
<?php
	$sql="SELECT * FROM tbl_product_type";
	$resType=mysql_query($sql);
			
	if(!$resType)
		dieN(mysql_error());	
?>
<form name="f" method="POST" onsubmit="return checkForm();" enctype="multipart/form-data">
	<input type="hidden" name="act" value="actionInsert"></input>
	<table class="tbl_action">
		<tr>
			<th>Mã</th>
			<td><input type="text" name='code'></input></td>
		</tr>		
		<tr>
			<th>Tên hàng <span style='color:#FF0000'>(*)</span></th>
			<td><input type="text" name='name'></input></td>
		</tr>
		<tr>
			<th>ĐVT <span style='color:#FF0000'>(*)</span></th>
			<td>
				<input type='radio' checked="checked"  name='check' onclick="document.getElementById('unit1').disabled=false;document.getElementById('unit2').disabled=true"></input>&nbsp;	
				<select name='unit' id='unit1' >
					<option value='Bộ'>Bộ</option>
					<option value='Cái'>Cái</option>
					<option value='Cây'>Cây</option>
					<option value='Chiếc'>Chiếc</option>
					<option value='Cuộn'>Cuộn</option>
					<option value='Đôi'>Đôi</option>
					<option value='M2'>M2</option>
					<option value='Sợi'>Sợi</option>
					<option value='Tấm'>Tấm</option>
				</select>
				<br>
				<input type='radio' name='check' onclick="document.getElementById('unit2').disabled=false;document.getElementById('unit1').disabled=true"></input>
				&nbsp;<input type="text" disabled="disabled" name='unit' id='unit2' value="<?php echo $row["unit"]?>"></input>
			</td>
		</tr>
		<!--<tr>
			<th>Đơn giá</th>
			<td><input style='text-align:right' type="text" name='price' onblur="displayNumeric(this)"></input></td>
		</tr>-->
		<tr>
			<th>Loại hàng</th>
			<td>
				<select name='product_type_id'>
					<?php 
					while($rowType = mysql_fetch_array($resType))
						echo "<option ".($row["product_type_id"]==$rowType["id"]?"selected='selected'":"")." value='$rowType[id]'>$rowType[name]</option>";
					?>
				</select>
			</td>
		</tr>
		<tr>
			<th>Trích dẫn</th>
			<td><input type="text" name='quote'></input></td>
		</tr>
		<tr>
			<th>Ghi chú</th>
			<td><textarea name='detail'></textarea></td>
		</tr>
		<tr>
			<th>Hình ảnh</th>
			<td><input type="file" name='image'></input></td>
		</tr>
		<tr>
			<th>Tiêu đề ảnh</th>
			<td><input type="text" name='alt'></input></td>
		</tr>
		<tr>
			<th></th>
			<th align="left">
				<input type="submit" value="Thêm"></input><input type="reset" value="Mặc định"></input><input type="button" value="Đóng" onclick="window.location='?zone=product'"></input>&nbsp;&nbsp;&nbsp;&nbsp;<span style='color:#FF0000;'>(*)</span> Thông tin bắt buộc
			</th>
		</tr>
	</table>
</form>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
<script type="text/javascript">
	var oFCKeditor = new FCKeditor('detail');
	oFCKeditor.Height	= "400";
	oFCKeditor.Width	= "650";
	oFCKeditor.ReplaceTextarea();
</script>